﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Gmantis.Controls
{
    public class VisibilityConverter : IValueConverter
    {
        // Methods
        public VisibilityConverter()
        {
            this.Opposite = false;
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool flag = object.Equals(parameter, "not") || this.Opposite;
            if ((value is bool) && (targetType == typeof(Visibility)))
            {
                return ((((bool)value) != flag) ? Visibility.Visible : Visibility.Collapsed);
            }
            if ((value is Visibility) && (targetType.GetNonNullableType() == typeof(bool)))
            {
                return ((((Visibility)value) == Visibility.Visible) != flag);
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return this.Convert(value, targetType, parameter, culture);
        }

        // Properties
        public bool Opposite { get; set; }
    }
}
